package com.zcah.system.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zcah.common.util.PageUtils;
import com.zcah.common.vo.Query;
import com.zcah.common.vo.R;
import com.zcah.system.domain.JwtuserDO;
import com.zcah.system.service.JwtuserService;
import com.zcah.system.shiro.Constants;

/**
 * jwt认证用户表
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-07-19 11:16:29
 */
 
@Controller
@RequestMapping("/system/jwtuser")
public class JwtuserController {

	private final JwtuserService jwtuserService;

	@Autowired
	public JwtuserController(JwtuserService jwtuserService) {
		this.jwtuserService = jwtuserService;
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresRoles(Constants.ROLE_ADMIN)
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<JwtuserDO> jwtuserList = jwtuserService.list(query);
		int total = jwtuserService.count(query);
		return new PageUtils(jwtuserList, total);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresRoles(Constants.ROLE_ADMIN)
	public R save( JwtuserDO jwtuser){
		if(jwtuserService.save(jwtuser)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresRoles(Constants.ROLE_ADMIN)
	public R update( JwtuserDO jwtuser){
		jwtuserService.update(jwtuser);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresRoles(Constants.ROLE_ADMIN)
	public R remove( Long id){
		if(jwtuserService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresRoles(Constants.ROLE_ADMIN)
	public R remove(@RequestParam("ids[]") Long[] ids){
		jwtuserService.batchRemove(ids);
		return R.ok();
	}
	
}
